package com.cnebula.openapi.auth.authtoken.impl;

import io.vertx.core.Future;
import io.vertx.core.Vertx;
import io.vertx.core.http.HttpClient;
import io.vertx.core.http.HttpClientOptions;
import io.vertx.core.logging.Logger;
import io.vertx.core.logging.LoggerFactory;

public class PrivilegeServiceImpl {

	private String okapiUrl = null;
	private Vertx vertx;
	private String requestToken;
	private String tenant;
	private int timeout = 10;
	private final Logger logger = LoggerFactory.getLogger("mod-auth-authtoken-module");

	public PrivilegeServiceImpl(Vertx vertx) {
		this.vertx = vertx;
	}

	public void setOkapiUrl(String url) {
		okapiUrl = url;
		if (!okapiUrl.endsWith("/")) {
			okapiUrl = okapiUrl + "/";
		}
	}

	public void setRequestToken(String token) {
		requestToken = token;
	}

	public void setTenant(String tenant) {
		this.tenant = tenant;
	}

	public Future<Void> checkSign() {
		Future<Void> future = Future.future();
		HttpClientOptions options = new HttpClientOptions();
		options.setConnectTimeout(timeout * 1000);
		HttpClient client = vertx.createHttpClient(options);
		String okapiUrlCandidate = "http://localhost:9130/";
		if (okapiUrl != null) {
			okapiUrlCandidate = okapiUrl;
		}

		return future;
	}
}
